package org.easydarwin.easyplayer.zhi;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.easydarwin.bean.Register;
import org.easydarwin.easyplayer.R;
import org.easydarwin.http.API;
import org.easydarwin.http.JSONUtils;
import org.easydarwin.http.Okhttp;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class RegistActivity extends Activity {

    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.et_phone_number)
    EditText etPhone;
    @BindView(R.id.et_pwd)
    EditText etMm;
    @BindView(R.id.et_pwd2)
    EditText etQrmm;
    @BindView(R.id.tv_login)
    TextView butRegist;
    @BindView(R.id.text)
    TextView text;
    @BindView(R.id.status_bar)
    View statusBar;
    @BindView(R.id.et_xingbie)
    EditText etXingbie;
    @BindView(R.id.et_diqu)
    EditText etDiqu;

    //    Z_Login_UserInfoDao z_userInfoDao;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
//        z_userInfoDao = new Z_Login_UserInfoDao(this);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.img_back, R.id.tv_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.tv_login:
                if (TextUtils.isEmpty(etPhone.getText().toString())) {
                    Toast.makeText(this, "请输入账号", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(etMm.getText().toString())) {
                    Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (etMm.getText().toString().length() < 6) {
                    Toast.makeText(this, "密码太短，请重新输入！", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(etQrmm.getText().toString())) {
                    Toast.makeText(this, "请输入用户名！", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(etXingbie.getText().toString())) {
                    Toast.makeText(this, "请输入性别！", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (TextUtils.isEmpty(etDiqu.getText().toString())) {
                    Toast.makeText(this, "请输入地区！", Toast.LENGTH_SHORT).show();
                    return;
                }

                API.register(etPhone.getText().toString(), etMm.getText().toString(), etQrmm.getText().toString(),
                        etXingbie.getText().toString(),etDiqu.getText().toString(),

                        new Okhttp.Objectcallback() {
                    @Override
                    public void onsuccess(String st) {
                        Log.e("99", "注冊" + st);
                        Register register = JSONUtils.parseJSON(st, Register.class);
                        if (register.getCode() == 10001) {
                            if (register.isIssuccess()) {
                                Toast.makeText(RegistActivity.this, register.getMsg(), Toast.LENGTH_SHORT).show();
                                finish();
                            } else {
                                Toast.makeText(RegistActivity.this, register.getMsg(), Toast.LENGTH_SHORT).show();
                            }
                        } else {

                        }

                    }

                    @Override
                    public void onFalia(int code, String errst) {
                        Toast.makeText(RegistActivity.this, "注冊网络错误！" + errst.toString(), Toast.LENGTH_SHORT).show();
                        Log.e("99", "注冊网络错误" + errst.toString());
                    }
                });

                break;
        }
    }
}
